<!DOCTYPE html>
<!-- 资质审核 -->
<html>
<head>
    <meta charset="utf-8">
    <title>企业资质审核</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../../css/main.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>企业资质审核</legend>
</fieldset>

<table class="layui-hide" id="test" lay-filter="tableFilter"></table>

<script type="text/html" id="switchTpl">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="sex" value="{{d.certificationstatus}}" lay-skin="switch" lay-text="已认证|未审核"
           lay-filter="sexDemo" {{
           d.certificationstatus=="2" ? 'checked' : '' }}>
</script>


<script src="../../lib/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use(['table', 'form', 'jquery', 'okLayer', 'okNprogress', 'okUtils'], function () {
        let table = layui.table
        let form = layui.form;
        let $ = layui.jquery;
        let okLayer = layui.okLayer;
        let okNprogress = layui.okNprogress;
        let okUtils = layui.okUtils;

        // 获取contentText
        const ctx = function () {
            let pathName = document.location.pathname;
            let index = pathName.substr(1).indexOf("/");
            let result = pathName.substr(0, index + 1);
            return result;
        }();
        let commpanytable = table.render({
            elem: '#test'
            , even: true
            , url: ctx + '/admin/findenterpriseQualificationlist'
            , cellMinWidth: 80
            , page: true
            , response: {statusCode: 200}
            , toolbar: "#toolbarTpl"
            , cols: [[
                {type: 'checkbox'}
                , {type: 'numbers'}
                , {field: 'enterpriseid', title: '企业id', width: 130, unresize: true,}
                , {field: 'enterprisename', title: '企业名称', width: 180, templet: '#usernameTpl'}
                , {
                    field: 'registercapital', title: '注册资本', width: 150, templet: function (d) {
                        return d.authInfomation ? d.authInfomation.registercapital || "" : ""
                    }
                }
                , {
                    field: 'brncode', title: '工商注册号', width: 180, templet: function (d) {
                        return d.authInfomation ? d.authInfomation.brncode || "" : ""
                    }
                }
                , {
                    field: 'industry', title: '计算机软件', width: 180, templet: function (d) {
                        return d.authInfomation ? d.authInfomation.industry || "" : ""
                    }, unresize: true
                }
                , {
                    field: 'scopeofbusiness', title: '经营范围', width: 130, templet: function (d) {
                        return d.authInfomation ? d.authInfomation.scopeofbusiness || "" : ""
                    }, unresize: true
                }
                , {field: 'certificationstatus', title: '认证状态', width: 130, templet: '#switchTpl', unresize: true}
                , {title: '操作', width: 130, templet: '#operationTpl', unresize: true}
            ]]
        });

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "batchPass":
                    batchPass();
                    break;
                case "batchFail":
                    batchFail(obj.data);
                    break;
            }
        })

        //批量通过
        function batchPass() {
            okLayer.confirm("确定批量通过审核吗？", function (index) {
                layer.close(index);
                var checkStatus = table.checkStatus("test");
                var rows = checkStatus.data.length;
                if (rows > 0) {
                    var idsStr = checkStatus.data;
                    if (idsStr) {
                        var idsStr = "";
                        for (var i = 0; i < rows; i++) {
                            idsStr += checkStatus.data[i].enterpriseid;
                            if (i != checkStatus.data.length - 1) {
                                idsStr += ","
                            }
                        }
                        $.ajax({
                            url: ctx + '/admin/batchReviewCompanies',
                            type: 'POST',
                            data: {"commpanys": idsStr, "status": "2"},
                            dataType: 'json',
                            error: function () {
                                okLayer.redCrossMsg("服务器错误")
                            },
                            success: function (data) {
                                if (data.code == 200) {
                                    // 业务正常
                                    okUtils.tableSuccessMsg(data.msg, function () {
                                        commpanytable.reload();
                                    });
                                    okNprogress.done();
                                } else {
                                    // 业务异常
                                    okLayer.yellowSighMsg(data.msg)
                                }
                            }
                        });
                    }
                    return idsStr;
                } else {
                    layer.msg("未选择有效数据", {offset: "t", anim: 6});
                }
            });
        }

        //批量不通过
        function batchFail(data) {
            okLayer.confirm("确定批量不通过审核吗？", function (index) {
                layer.close(index);
                var checkStatus = table.checkStatus("test");
                var rows = checkStatus.data.length;
                if (rows > 0) {
                    var idsStr = checkStatus.data;
                    if (idsStr) {
                        var idsStr = "";
                        for (var i = 0; i < rows; i++) {
                            idsStr += checkStatus.data[i].enterpriseid;
                            if (i != checkStatus.data.length - 1) {
                                idsStr += ","
                            }
                        }
                        $.ajax({
                            url: ctx + '/admin/batchReviewCompanies',
                            type: 'POST',
                            data: {"commpanys": idsStr, "status": "3"},
                            dataType: 'json',
                            error: function () {
                                okLayer.redCrossMsg("服务器错误")
                            },
                            success: function (data) {
                                if (data.code == 200) {
                                    // 业务正常
                                    okUtils.tableSuccessMsg(data.msg, function () {
                                        commpanytable.reload();
                                    });
                                    okNprogress.done();
                                } else {
                                    // 业务异常
                                    okLayer.yellowSighMsg(data.msg)
                                }
                            }
                        });
                    }
                    return idsStr;
                } else {
                    layer.msg("未选择有效数据", {offset: "t", anim: 6});
                }
            });
        }

    })
</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="batchPass">批量通过</button>
        <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="batchFail">批量不通过</button>
    </div>
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
    <a class="layui-btn layui-btn-xs" lay-event="pass">通过</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="fail">不通过</a>
</script>
</body>
</html>